package com.example.demo.controller;

import com.example.demo.model.MessageInfo;
import com.example.demo.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;

/**
 * ClassName: MessageController
 * Package: IntelliJ IDEA
 * Description:
 *
 * @Author 谷京京
 * @Create 2023/10/30 15:53
 * @Version 1.0
 */
@RequestMapping("/message")
@RestController
@Slf4j
public class MessageController {
    @Autowired
    private MessageService messageService;
    @RequestMapping("/publish")
    public Boolean publishMessage(MessageInfo messageInfo) {
        if(!StringUtils.hasLength(messageInfo.getTo())
            || !StringUtils.hasLength(messageInfo.getFrom())
            || !StringUtils.hasLength(messageInfo.getMessage())) {
            return false;
        }
        messageService.addMessage(messageInfo);
        return true;
    }
    @RequestMapping("/getMessageInfo")
    public List<MessageInfo> getMessageInfo() {
        return messageService.getMessageInfo();
    }
}
